package cn.stylefeng.guns.modular.manager.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.*;
import cn.stylefeng.guns.modular.manager.model.params.*;
import cn.stylefeng.guns.modular.manager.service.*;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 服务点控制器
 *
 * @author yumker
 * @Date 2021-01-07 18:28:50
 */
@Controller
@RequestMapping("/flowStoreCity")
public class FlowStoreCityController extends BaseController {

    private String PREFIX = "/manager/flowStoreCity";

    @Autowired
    private FlowStoreCityService flowStoreCityService;
    @Autowired
    private FlowServiceTypeService flowServiceTypeService;

    @Autowired
    private FlowGoodsService flowGoodsService;

    @Autowired
    private FlowGoodsPriceService flowGoodsPriceService;

    @Autowired
    private FlowServiceTypePriceService flowServiceTypePriceService;
    @Autowired
    private FlowElevatorPriceService flowElevatorPriceService;
    @Autowired
    private FlowFloorLevelService flowFloorLevelService;
    @Autowired
    private FlowGoodsTypeService flowGoodsTypeService;

    /**
     * 跳转到主页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/flowStoreCity.html";
    }

    /**
     * 新增页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/flowStoreCity_add.html";
    }

    /**
     * 编辑页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/flowStoreCity_edit.html";
    }

    /**
     * 新增接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(FlowStoreCityParam flowStoreCityParam) {
        this.flowStoreCityService.add(flowStoreCityParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(FlowStoreCityParam flowStoreCityParam) {
        this.flowStoreCityService.update(flowStoreCityParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(FlowStoreCityParam flowStoreCityParam) {
        this.flowStoreCityService.delete(flowStoreCityParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(FlowStoreCityParam flowStoreCityParam) {
        FlowStoreCity detail = this.flowStoreCityService.getById(flowStoreCityParam.getStoreCityId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(FlowStoreCityParam flowStoreCityParam) {
        return this.flowStoreCityService.findPageBySpec(flowStoreCityParam);
    }

    /**
     * 编辑页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowGoods")
    public String flowGoods() {
        return PREFIX + "/flowGoods.html";
    }

    /**
     * 编辑页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/region")
    public String region() {
        return PREFIX + "/flowRegion.html";
    }

    /**
     * 编辑页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowServiceType")
    public String flowServiceType() {
        return PREFIX + "/flowServiceType.html";
    }


    /**
     * 查询列表
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @ResponseBody
    @RequestMapping("/flowGoodsList")
    public LayuiPageInfo list(FlowGoodsParam flowGoodsParam) {
        return this.flowGoodsService.customGoodsPageList(flowGoodsParam);
    }

    /**
     * 查询列表
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @ResponseBody
    @RequestMapping("/flowServiceTypeList")
    public LayuiPageInfo flowServiceTypeList(FlowServiceTypeParam flowServiceTypeParam) {
        return this.flowServiceTypeService.customCarPageList(flowServiceTypeParam);
    }

    @RequestMapping("/flowGoodsPriceEdit")
    public String flowGoodsPriceEdit() {
        return PREFIX + "/flowGoodsPrice_edit.html";
    }

    //查询
    /**
     * 编辑接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowGoodsPriceEditItem")
    @ResponseBody
    public ResponseData flowGoodsPriceEditItem(FlowGoodsPriceParam flowGoodsPriceParam) {
        QueryWrapper<FlowGoodsPrice> goodsPriceQueryWrapper = new QueryWrapper<>();
        goodsPriceQueryWrapper.eq("goods_id",flowGoodsPriceParam.getGoodsId());
        goodsPriceQueryWrapper.eq("store_city_id",flowGoodsPriceParam.getStoreCityId());

        FlowGoodsPrice detail = this.flowGoodsPriceService.getOne(goodsPriceQueryWrapper);
        if(detail == null){
            this.flowGoodsPriceService.add(flowGoodsPriceParam);
        }else {
            this.flowGoodsPriceService.update(flowGoodsPriceParam);
        }

        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowGoodsPriceDetail")
    @ResponseBody
    public ResponseData flowGoodsPriceDetail(FlowGoodsPriceParam flowGoodsPriceParam) {
        QueryWrapper<FlowGoodsPrice> goodsPriceQueryWrapper = new QueryWrapper<>();
        goodsPriceQueryWrapper.eq("goods_id",flowGoodsPriceParam.getGoodsId());
        goodsPriceQueryWrapper.eq("store_city_id",flowGoodsPriceParam.getStoreCityId());

        FlowGoodsPrice detail = this.flowGoodsPriceService.getOne(goodsPriceQueryWrapper);
        if(detail == null){
            detail = new FlowGoodsPrice();
            detail.setGoodsId(flowGoodsPriceParam.getGoodsId());
            detail.setStoreCityId(flowGoodsPriceParam.getStoreCityId());
        }
        return ResponseData.success(detail);
    }


    @RequestMapping("/flowServiceTypePriceEdit")
    public String flowServiceTypePriceEdit() {
        return PREFIX + "/flowServiceTypePrice_edit.html";
    }

    /**
     * 删除接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowServiceTypePriceDetail")
    @ResponseBody
    public ResponseData flowServiceTypePriceDetail(FlowServiceTypePriceParam flowServiceTypePriceParam) {
        QueryWrapper<FlowServiceTypePrice> flowServiceTypePriceQueryWrapper = new QueryWrapper<>();
        flowServiceTypePriceQueryWrapper.eq("service_type_id",flowServiceTypePriceParam.getServiceTypeId());
        flowServiceTypePriceQueryWrapper.eq("store_city_id",flowServiceTypePriceParam.getStoreCityId());

        FlowServiceTypePrice detail = this.flowServiceTypePriceService.getOne(flowServiceTypePriceQueryWrapper);
        if(detail == null){
            detail = new FlowServiceTypePrice();
            detail.setServiceTypeId(flowServiceTypePriceParam.getServiceTypeId());
            detail.setStoreCityId(flowServiceTypePriceParam.getStoreCityId());
        }
        return ResponseData.success(detail);
    }

    //查询
    /**
     * 编辑接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowServiceTypePriceEditItem")
    @ResponseBody
    public ResponseData flowServiceTypePriceEditItem(FlowServiceTypePriceParam flowServiceTypePriceParam) {
        QueryWrapper<FlowServiceTypePrice> flowServiceTypePriceQueryWrapper = new QueryWrapper<>();
        flowServiceTypePriceQueryWrapper.eq("service_type_id",flowServiceTypePriceParam.getServiceTypeId());
        flowServiceTypePriceQueryWrapper.eq("store_city_id",flowServiceTypePriceParam.getStoreCityId());

        FlowServiceTypePrice detail = this.flowServiceTypePriceService.getOne(flowServiceTypePriceQueryWrapper);
        if(detail == null){
            this.flowServiceTypePriceService.add(flowServiceTypePriceParam);
        }else {
            this.flowServiceTypePriceService.update(flowServiceTypePriceParam);
        }

        return ResponseData.success();
    }

    //楼层的费用

    /**
     * 编辑页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowElevatorPrice")
    public String flowElevatorPrice() {
        return PREFIX + "/flowElevatorPrice.html";
    }
    /**
     * 查询列表
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @ResponseBody
    @RequestMapping("/flowElevatorPriceList")
    public LayuiPageInfo flowElevatorPriceList(FlowFloorLevelParam flowFloorLevelParam) {
        return this.flowFloorLevelService.customFloorPageList(flowFloorLevelParam);
    }

    @RequestMapping("/flowElevatorPriceEdit")
    public String flowElevatorPriceEdit() {
        return PREFIX + "/flowElevatorPrice_edit.html";
    }

    /**
     * 删除接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowElevatorPriceDetail")
    @ResponseBody
    public ResponseData flowElevatorPriceDetail(FlowElevatorPriceParam elevatorPriceParam) {
        QueryWrapper<FlowElevatorPrice> flowElevatorPriceQueryWrapper = new QueryWrapper<>();
        flowElevatorPriceQueryWrapper.eq("elevator_id",elevatorPriceParam.getElevatorId());
        flowElevatorPriceQueryWrapper.eq("store_city_id",elevatorPriceParam.getStoreCityId());
        flowElevatorPriceQueryWrapper.eq("service_type_id",elevatorPriceParam.getServiceTypeId());
        FlowElevatorPrice detail = this.flowElevatorPriceService.getOne(flowElevatorPriceQueryWrapper);
        if(detail == null){
            detail = new FlowElevatorPrice();
            detail.setStoreCityId(elevatorPriceParam.getStoreCityId());
            detail.setElevatorId(elevatorPriceParam.getElevatorId());
            detail.setServiceTypeId(elevatorPriceParam.getServiceTypeId());
        }
        return ResponseData.success(detail);
    }

    /**
     * 编辑接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/flowElevatorPriceEditItem")
    @ResponseBody
    public ResponseData flowElevatorPriceEditItem(FlowElevatorPriceParam elevatorPriceParam) {
        QueryWrapper<FlowElevatorPrice> flowElevatorPriceQueryWrapper = new QueryWrapper<>();
        flowElevatorPriceQueryWrapper.eq("elevator_id",elevatorPriceParam.getElevatorId());
        flowElevatorPriceQueryWrapper.eq("store_city_id",elevatorPriceParam.getStoreCityId());
        flowElevatorPriceQueryWrapper.eq("service_type_id",elevatorPriceParam.getServiceTypeId());
        FlowElevatorPrice detail = this.flowElevatorPriceService.getOne(flowElevatorPriceQueryWrapper);
        if(detail == null){
            this.flowElevatorPriceService.add(elevatorPriceParam);
        }else {
            this.flowElevatorPriceService.update(elevatorPriceParam);
        }

        return ResponseData.success();
    }

    @RequestMapping("/storeList")
    @ResponseBody
    public ResponseData storeList(){
        return ResponseData.success(flowStoreCityService.list());
    }


    @RequestMapping("/goodsType")
    @ResponseBody
    public ResponseData goodsType(){
        return ResponseData.success(flowGoodsTypeService.list());
    }
}


